

package example.serialization;

import com.hazelcast.nio.serialization.compact.CompactReader;
import com.hazelcast.nio.serialization.compact.CompactSerializer;
import com.hazelcast.nio.serialization.compact.CompactWriter;

import javax.annotation.Nonnull;

public class SerializableEmployeeDTOSerializer implements CompactSerializer<SerializableEmployeeDTO> {
    @Nonnull
    @Override
    public SerializableEmployeeDTO read(@Nonnull CompactReader reader) {
        return new SerializableEmployeeDTO(reader.readString("name"), reader.readInt32("age"));
    }

    @Override
    public void write(@Nonnull CompactWriter writer, @Nonnull SerializableEmployeeDTO object) {
        writer.writeString("name", object.getName());
        writer.writeInt32("age", object.getAge());
    }

    @Nonnull
    @Override
    public String getTypeName() {
        return SerializableEmployeeDTO.class.getName();
    }

    @Nonnull
    @Override
    public Class<SerializableEmployeeDTO> getCompactClass() {
        return SerializableEmployeeDTO.class;
    }
}
